package com.runen.infinitemovement.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.runen.infinitemovement.R;
import com.runen.infinitemovement.tool.CommonUtil;

/**
 * Create by LiaoDuanHong
 * Create on 2021/01/12 20:43
 */
public class SignInAdapter extends BaseQuickAdapter<Integer, BaseViewHolder> {
    private Context context;
    private int day;

    public void setDay(int day) {
        this.day = day;
    }

    public SignInAdapter(Context context) {
        super(R.layout.item_sign_in);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder holder, Integer item) {
        LinearLayout ll_day = holder.getView(R.id.ll_day);
        LinearLayout ll_day7 = holder.getView(R.id.ll_day7);
        TextView tv_sign_in_day = holder.getView(R.id.tv_sign_in_day);
        TextView tv_add_hozm_num = holder.getView(R.id.tv_add_hozm_num);
        TextView tv_sign_in_day7 = holder.getView(R.id.tv_sign_in_day7);
        TextView tv_discribel = holder.getView(R.id.tv_discribel);
        TextView tv_add_hozm_num7 = holder.getView(R.id.tv_add_hozm_num7);
        String itemDay = "第%s天";
        String add_hozom = "+%s火种";
        int width = CommonUtil.getScreenHW((Activity) context)[0];
        int setWidth = (width - CommonUtil.dp2px(context, 50)) / 5;
        if (item >= 7) {
            ll_day.setVisibility(View.GONE);
            ll_day7.setVisibility(View.VISIBLE);
            tv_sign_in_day7.setText(String.format(itemDay, item));

            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) ll_day.getLayoutParams();
            layoutParams.width = setWidth * 7 / 3;
            layoutParams.rightMargin = setWidth / 3;
            ll_day7.setLayoutParams(layoutParams);
        } else {
            ll_day.setVisibility(View.VISIBLE);
            ll_day7.setVisibility(View.GONE);
            tv_sign_in_day.setText(String.format(itemDay, item));

            //重新测量宽度
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) ll_day.getLayoutParams();
            layoutParams.width = setWidth;
            layoutParams.rightMargin = setWidth / 3;
            ll_day.setLayoutParams(layoutParams);
        }

        switch (item) {
            case 1:
                tv_add_hozm_num.setText(String.format(add_hozom, 1));
                break;
            case 2:
                tv_add_hozm_num.setText(String.format(add_hozom, 2));
                break;
            case 3:
                tv_add_hozm_num.setText(String.format(add_hozom, 4));
                break;
            case 4:
                tv_add_hozm_num.setText(String.format(add_hozom, 5));
                break;
            case 5:
                tv_add_hozm_num.setText(String.format(add_hozom, 8));
                break;
            case 6:
                tv_add_hozm_num.setText(String.format(add_hozom, 10));
                break;
            default:
                tv_add_hozm_num7.setText(String.format(add_hozom, 15));
                break;
        }
        if (item <= day) {
            tv_sign_in_day.setTextColor(CommonUtil.getColor(R.color.white));
            tv_add_hozm_num.setTextColor(CommonUtil.getColor(R.color.white));
            ll_day.setBackground(CommonUtil.getDrawable(R.drawable.bg_ffee4238_df2526_cr_dp6));
        } else {
            tv_sign_in_day.setTextColor(CommonUtil.getColor(R.color.color_333333));
            tv_add_hozm_num.setTextColor(CommonUtil.getColor(R.color.color_FFC0C1C5));
            ll_day.setBackground(CommonUtil.getDrawable(R.drawable.bg_f6f7fb_cr_6dp));
        }
        if (day == 7) {
            tv_sign_in_day7.setTextColor(CommonUtil.getColor(R.color.white));
            tv_discribel.setTextColor(CommonUtil.getColor(R.color.white));
            tv_add_hozm_num7.setTextColor(CommonUtil.getColor(R.color.white));
            ll_day7.setBackground(CommonUtil.getDrawable(R.drawable.bg_ffee4238_df2526_cr_dp6));
        } else {
            tv_sign_in_day7.setTextColor(CommonUtil.getColor(R.color.color_333333));
            tv_discribel.setTextColor(CommonUtil.getColor(R.color.color_FFC0C1C5));
            tv_add_hozm_num7.setTextColor(CommonUtil.getColor(R.color.color_FFC0C1C5));
            ll_day7.setBackground(CommonUtil.getDrawable(R.drawable.bg_f6f7fb_cr_6dp));
        }
    }
}
